/**
*	@file    \C\2.cpp
*	@date    2013-10-6 17:25
*	@author  Il'yas Garipov <logirz728@gmail.com>
*
*	Prime deliver-er
*
*	@version 1.0.1s
*
*	@par Input is a single natual number less than 10000.
*	@par Output is the n-th prime number
*/

#include <stdio.h>
#include <math.h>
#include <assert.h>

#define MAX_N 10000 //!< To pierce textual outputs

#ifndef NDEBUG
	#define DOUT( toprint ) printf( "\n# " toprint )	//!< Debug output, prints a plain text line preceded by #
	#define DPUT( toput , x ) printf( "\n# " toput , x )//!< Debug put, a DOUT with a single variable inside
	#define DLN											//!< Debug line, doesn't exist in release (with NDEBUG defined)
	#define DPUTCLOSURE	DOUT("=============================================================================");\
						DPUT("FILE: %s", __FILE__ );\
						DPUT("COMPILATION DATE: %s", __DATE__ );\
						DPUT("COMPILATION TIME: %s", __TIME__ )//!< Put a closing statement, complete with datestamp and finename.
#else
	#define DOUT
	#define DPUT
	#define DLN if(0)
	#define DPUTCLOSURE
#endif



int main()
{
	DOUT("=======================2007, 1 semester assignment, 2-C=======================\n");
	DOUT("==============================================================================\n");
	DOUT("Please enter the number of the prime number to output(less or equal to MAX_N):\n");
	DOUT("> ");

	long long int n = 0;    //n is long long because that'll lead to more reliable asserts
	int chk = scanf("%lld", &n);
	DLN assert(("You have entered a single number" , chk == 1));
	DLN assert(("N is actually less than MAX_N" , (n < MAX_N)));

	long int nPrimes[(1 + MAX_N)] = {2, 3, 5};//Reliability boosts. Call them crutches if you want to
	long int lastprime = 3,	//Number of block after last prime's block in nPrimes
	         curr = 1;		//These lines need re-doing if any upscaling is to take place

	while(! nPrimes[n]) {
		bool prime = 1;		//is the "curr" prime?
		++curr;

		for(int i = 0; i < lastprime; i++) {
			if(!(curr % nPrimes[i])) {
				prime = 0;
				break;
			}
		}

		if(prime) {
			nPrimes[lastprime] = curr;
			++lastprime;
		}
	}



	printf("%ld\n", nPrimes[n - 1]);
	
	DPUTCLOSURE;

	return 0;
}
